package com.yociyy.config;

import com.yociyy.security.authentication.YoCiUser;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * 用户信息业务流程实现
 * 
 * @author: YoCiyy
 * @date: 2020/6/3
 */
@Slf4j
@Component
@AllArgsConstructor
public class UserDetailBiz implements UserDetailsService {

	private final PasswordEncoder passwordEncoder;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		Collection<? extends GrantedAuthority> authorities
				= AuthorityUtils.createAuthorityList("ROLE_USER");
		Set<String> permissions = new HashSet<>();
		permissions.add("sys:user:admin");
		return new YoCiUser(1L, 1L, permissions, "user_1", passwordEncoder.encode("123456"), true, true, true, true, authorities);

	}
}
